//
//  main.m
//  OC6_限时代码10遍
//
//  Created by dllo on 15/11/4.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

    
    // 1
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"市", areaArr, @"区", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    
    // 2
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"市", areaArr, @"区", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    
    // 3
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", areaArr, @"市", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//        NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//        NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//        NSLog(@"%@", str1);
    
    // 4
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", areaArr, @"市", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    // 5
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"市", areaArr, @"区", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    // 6
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"市", areaArr, @"区", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    // 7
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"省", cityArr, @"市", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"shi", areaArr, @"qu", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    //8
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"sheng", cityArr, @"shi", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"sheng", areaArr, @"shi", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    // 9
//    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
//    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//    NSArray *arr = [str componentsSeparatedByString:@"\n"];
//    NSMutableArray *proArr = [NSMutableArray array];
//    NSMutableArray *cityArr = nil;
//    NSMutableArray *areaArr = nil;
//    for (NSInteger i = 0; i < arr.count; i++) {
//        NSString *temp = [arr objectAtIndex:i];
//        if (![temp hasPrefix:@" "]) {
//            cityArr = [NSMutableArray array];
//            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"sheng", cityArr, @"shi", nil];
//            [proArr addObject:proDic];
//        } else if (![temp hasPrefix:@"   "]) {
//            areaArr = [NSMutableArray array];
//            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"sheng", areaArr, @"shi", nil];
//            [cityArr addObject:cityDic];
//        } else {
//            [areaArr addObject:temp];
//        }
//    }
//    
//    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
//    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSLog(@"%@", str1);
    
    // 10
    NSString *path = @"/Users/dllo/Desktop/省市区/area.txt";
    NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSArray *arr = [str componentsSeparatedByString:@"\n"];
    NSMutableArray *proArr = [NSMutableArray array];
    NSMutableArray *cityArr = nil;
    NSMutableArray *areaArr = nil;
    for (NSInteger i = 0; i < arr.count; i++) {
        NSString *temp = [arr objectAtIndex:i];
        if (![temp hasPrefix:@" "]) {
            cityArr = [NSMutableArray array];
            NSMutableDictionary *proDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"sheng", cityArr, @"市", nil];
            [proArr addObject:proDic];
        } else if (![temp hasPrefix:@"   "]) {
            areaArr = [NSMutableArray array];
            NSMutableDictionary *cityDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:temp, @"sheng", areaArr, @"市", nil];
            [cityArr addObject:cityDic];
        } else {
            [areaArr addObject:temp];
        }
    }
    
    NSData *data = [NSJSONSerialization dataWithJSONObject:proArr options:NSJSONWritingPrettyPrinted error:nil];
    NSString *str1 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"%@", str1);
    
    
    
    
    
    
    
    
    return 0;
}
